layui.use(['form','layer','laydate','table','laytpl'],function(){

    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;



    const pVue=new Vue({
        el: '#permission',
        data:{
            all_data:null
        },
        methods:{
            getAllPerm:function(){
                this.$http.post(global_url+'/admin/permission')
                    .then(
                        response=>{
                    this.all_data=response.body.datas;
                table.render({
                    elem: '#permission',
                    cellMinWidth : 95,
                    page : true,
                    height: 312,
                    cols : [[
                        {field:"id", title: 'ID', width: 60, fixed:"left",sort:"true", align:'center'},
                        {field: 'name', title: '权限名称', edit: 'text', align:'center'},
                        {field: 'url', title: 'url', sort:"true", align:'center',edit: 'text'},
                        {field: 'descritpion', title: '描述', sort:"true",minWidth:20, align:'center',edit: 'text'},
                        {title: '操作', minWidth:170, templet:'#permissionBar',fixed:"right",align:"center"}
                    ]],
                    data:this.all_data,

                });

            },
                response=>{
                    layer.msg(response.body.status)
                })

            },
            updataPerm:function (data) {

                this.$http.post(global_url+'/admin/permission/updata',data)
                    .then(
                        response=>{
                            layer.msg(response.body.datas);
                            this.getAllPerm();
                         },
                        response=>{
                            layer.msg(response.body.datas);
                        }
                    )


            },
            deletePerm:function (data) {
                this.$http.post(global_url+'/admin/deleteurl',data)
                    .then(
                        response=>{

                             layer.msg(response.body.datas);
                            this.getAllPerm();

                        },
                        response=>{
                            layer.msg(response.body.datas);
                        }
                    )
            }
        }

    });

    pVue.getAllPerm();


    //列表操作
    table.on('tool(permission)', function(obj) {
        var layEvent = obj.event,
            data = obj.data;

        if(layEvent=="edit"){
            pVue.updataPerm(data)
        }else if(layEvent=="deletePerm"){
            pVue.deletePerm(data)
        }
        console.log(data)


    });

})